home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 435 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.1 KB

  1. From: kanze@gabi-soft.fr (J. Kanze)
  2. Message-ID: <KANZE.96Feb22144232@gabi.gabi-soft.fr>
  3. X-Original-Date: 22 Feb 1996 13:42:32 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 22 Feb 96 14:11:31 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: An STL helper -- and template and type shenanigans
  9. Organization: GABI Software, Sarl.
  10. References: <01BAEFD6.AD7E8620@dino.int.com>
  11.     <KANZE.96Feb1141158@slsvewt.lts.sel.alcatel.de>
  12.     <4eto87$9kf@hermes.synopsys.com> <KANZE.96Feb9171756@gabi.gabi-soft.fr>
  13.     <4gfg21$iga@caesar.ultra.net>
  14. In-Reply-To: phalpern@truffle.ultranet.com's message of 21 Feb 1996 09:56:42 PST
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBFAgUBMSx50+EDnX0m9pzZAQElDQF/eI4zYNDf6C2XA9gwkRqQrugOL9NNVktS
  17.     89r8gpIkTGjrtGH8+ZuJ/7OZ6NQK016A
  18.     =fFOG
  19.  
  20. In article <4gfg21$iga@caesar.ultra.net> phalpern@truffle.ultranet.com
  21. (Pablo Halpern) writes:
  22.  
  23. |> kanze@gabi.gabi-soft.fr (J. Kanze) wrote:
  24.  
  25. |> >In article <4eto87$9kf@hermes.synopsys.com> jbuck@Synopsys.COM (Joe
  26. |> >Buck) writes:
  27. |> >> The *language*, not just STL, requires copy constructors that actually
  28. |> >> copy.  The language automatically uses the copy constructor whenever it
  29. |> >> needs to make a copy.  The copy constructor is used to return objects
  30. |> >> from functions and to pass them in by value.  This usaga assumes that
  31. |> >> you get an actual copy.  Copy constructors can be optimized away in
  32. |> >> certain circumstances.  Again, this optimization works based on the
  33. |> >> assumption that a copy constructor does a copy, so you can avoid the
  34. |> >> copy by constructing the object in the right place.  It also means that
  35. |> >> having a side effect in the copy constructor (other than something that
  36. |> >> preserves copy semantics, like reference counting and such) is going to
  37. |> >> break things.
  38.  
  39. |> >In all cases where the language (outside of the library) does an
  40. |> >implicite copy, the object being copied is destructed immediately after,
  41. |> >before the user can use it for anything else.  So a `copy' that in fact
  42. |> >`moves' will still work.
  43.  
  44. |> Hmmm... I take it that you don't consider pass-by-value to be an
  45. |> implicit copy? Perhaps you're right, but I don't really see where the
  46. |> implicit vs. explicit question enters into this. I consider it an axiom
  47. |> that if you assign "a = b" that you can then assume that "a == b" is
  48. |> true unless a or b are volatile. If you write a copy constructor or
  49. |> assignment operator such that this is NOT true, then you are asking for
  50. |> trouble, IMHO. This leaves me with a delema wrt auto_ptr<> because,
  51. |> while I like what it is trying to do, I don't like the idea of breaking
  52. |> fundamental axioms in such a flagrant way. This could cause a ripple
  53. |> effect. I'm not sure what kinds of compiler optimizations might not be
  54. |> possible or even if certain semantics might become unpredicatable in
  55. |> this case. Maybe I'm overstating the problem. Auto_ptr<> semantics seem
  56. |> simple enough on the face of it and maybe this isn't a problem in
  57. |> reality. (Programming, especially in C++, is not expected to be the same
  58. |> as mathmatics, after all.)
  59.  
  60. You're not overstating anything.  You have precisely described the
  61. dilemma concerning auto_ptr, and why there is so much discussion about
  62. it.
  63.  
  64. In general, I agree with the concerning voiced about the changed
  65. semantics of operator=.  In the case of auto_ptr, however, in all of the
  66. cases where I think one would reasonably want to use it, the value on
  67. the right hand side is either a temporary, or a value about to disappear
  68. anyway.  So the changed semantics don't bother me too much.
  69. -- 
  70. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  71. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  72. Conseils, itudes et rialisations en logiciel orienti objet --
  73.               -- A la recherche d'une activiti dans une region francophone
  74. ---
  75. [ To submit articles: try just posting with your news-reader.
  76.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  77.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  78.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  79.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  80. ]
  81.